package fr.adfm.managedbean;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.event.AjaxBehaviorEvent;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import fr.adfm.dto.ArticleDto;
import fr.adfm.dto.ArticlePanierDto;
import fr.adfm.dto.PanierDto;
import fr.adfm.service.facade.Facade;

@Component
@Scope("request")
public class PanierCtrl implements Serializable{
	private static final long serialVersionUID = 1L;

	@Autowired
	private Facade facade;
	
	@Autowired
	private SessionManager sessionManager;
	
	public PanierDto getPanier() {
		return sessionManager.getPanier();
	}
	
	public void actionChangeQuantite(AjaxBehaviorEvent e) {
		System.out.println("actionChangeQuantite");
	}

	public ArticlePanierDto[] getAllArticlePanier(){
		Collection<ArticlePanierDto> articles =  sessionManager.getPanier().getArticles();
		return articles.toArray(new ArticlePanierDto[articles.size()]);
	}

	public String actionSupprimer(ArticlePanierDto value){
		sessionManager.getPanier().getArticles().remove(value);
		return null;
	};
	
}
